﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'auction';
domain = 'http://img1.chinalaohu.com';
</cfscript>
<cfparam name="platform" default="0" >

<cffunction name="list" access="remote" returntype="any" returnFormat="json">
<!---<cftry>--->

	
	
  <cfparam name="page" default="0">
  <cfparam name="asid" default="0">
  <!---查找专场--->
  <cfif isdefined('aid') and isnumeric(aid)>
  	<cfquery datasource="#DB#" name="searchasid">
    select asid 
    from #dbt#
    where aid = #aid#
    </cfquery>
    <cfscript>
		if (searchasid.recordcount gt 0){
			asid = searchasid.asid;
		}
		else {
			//"msg":"拍卖品不存在"
			return {"success":"0"};
		}
		</cfscript>
	</cfif>
  
  <cfscript>
	/*if (not isdefined('pagesize')){
		pagesize = 10;
	}*/
	
	if (isdefined('order')){
		switch(order){
			case 1:
				orderby = 'endtime ASC';
			  break;
			case 2:
				orderby = 'if(lastprice = 0,startprice,lastprice) DESC';
			  break;
			case 3:
				orderby = 'if(lastprice = 0,startprice,lastprice) ASC';
			  break;
			case 4:
				orderby = 'bids DESC';
			  break;
			default:
				orderby = 'aid DESC';
			  break;
		}
	}
	</cfscript>
  
  <cfquery datasource="#DB#" name="auctionrc">
  select aid from (select * from auction where asid=#asid# and atag > 0 AND prevtime <= #now()# order by acode asc) as temp  where asid=#asid# and aid not in (#aid#) group by leixin order by acode asc
  </cfquery>
  
  <cfscript>
	aidlist = valuelist(auctionrc.aid);
	if (aidlist eq '') aidlist = 0;
	</cfscript>
    <cfquery datasource="#DB#" name="auctionlist"> 
    SELECT
    auction.aid AS aaid,
    auction.atype,
    auction.atag,
    acode,
    auction.auction AS aname,
    auction.startprice,
    auction.oneprice,
    auction.lastprice,
    if(lastprice = 0,startprice,lastprice) as showprice,
    prevtime,
    starttime,
    endtime,
    auction_gallery.img_waterfall,leixin
    FROM
    auction
    INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
    WHERE 
    auction.aid in (#aidlist#)
    <cfif isdefined('orderby')>
    ORDER BY #orderby#
    </cfif>
    <!---<cfif isdefined('page') and isnumeric(page)>limit #page * pagesize#,#pagesize#</cfif>--->
    </cfquery>


<!---会员相关--->  
<cfif isdefined('uuid') and len(uuid) gte 32>
<!---关注--->
<cfquery datasource="#DB#" name="usergzlist">
select aid
from user_concern
INNER JOIN user_base ON user_base.uid = user_concern.uid
where user_base.muuid = '#uuid#'
</cfquery>
<cfscript>
if (usergzlist.recordcount gt 0){
	usergz = valuelist(usergzlist.aid);
}
else {
	usergz = '';
}
</cfscript>
</cfif>
<cfscript>
rs = StructNew();
StructAppend(rs,{"success":"1"});
</cfscript>

<cfscript>
//StructAppend(rs,{"count":auctionrc.recordcount});
StructAppend(rs,{"serverTime":datetimeformat(now(),'yyyy-mm-dd HH:nn:ss')});
list = arraynew(1);
/*if (auctionrc.rc gt 0){
	//品牌才有图片
	if (not isdefined('is_filter')){
		arrayappend(list,{"imgUrl":"http://192.168.6.104/app/pic/home_darktea.jpg"});
	}
}*/
</cfscript>
<!---顶部图片

<cfif page eq 0 AND auctionrc.recordcount gt 0 and not isdefined('is_filter')>
	<cfif isdefined('cateId') and cateId gt 0>
  	<!---分类图片显示--->
  	<cfquery datasource="#DB#" name="classimg">
    select pcimgurl
    from pin_class
    where pcid = #cateId#
    </cfquery>
    <cfscript>
		if (classimg.recordcount gt 0 and len(classimg.pcimgurl) gt 7){
			arrayappend(list,{"imgUrl":classimg.pcimgurl});
		}
		</cfscript>
  <cfelseif isdefined('brandId') and brandId gt 0>  
  	<!---分品牌图片显示--->
  	<cfquery datasource="#DB#" name="brandimg">
    select pbimgurl
    from pin_brands
    where pbid = #brandId#
    </cfquery>
    <cfscript>
		if (brandimg.recordcount gt 0 and len(brandimg.pbimgurl) gt 7){
			arrayappend(list,{"imgUrl":brandimg.pbimgurl});
		}
		</cfscript>
  </cfif>
</cfif>--->

<cfoutput query="auctionlist">
<cfscript>
attention = 0;
if (isdefined('usergz') and usergz neq ''){
	if (listfind(usergz,aaid) gt 0){
		attention = 1;
	}
}

switch(platform){
	case 0:
		iconUrl = domain & img_waterfall;
		if (left(img_waterfall,8) eq '/upload/' and left(img_waterfall,13) neq '/upload/adio/'){
			iconUrl = domain & replacenocase(img_waterfall,'/upload/','/upload/adio/');
		}
		break;
	case 1:
		iconUrl = domain & img_waterfall;
		if (left(img_waterfall,8) eq '/upload/' and left(img_waterfall,12) neq '/upload/ios/'){
			iconUrl = domain & replacenocase(img_waterfall,'/upload/','/upload/ios/');
		}
		break;
}


listjson = {
"aID":aaid,
"auctionCode": acode,
"iconUrl":iconUrl,
"name":aname,
"price":showprice,
"attention":attention
};
if (DateCompare(now(), endtime) gte 0){
	auctionType = 2;//成交
	structappend(listjson,{"dealTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), starttime) gte 0){
	auctionType = 1;//拍卖
	structappend(listjson,{"lastTime":datetimeformat(endtime,'yyyy-mm-dd HH:nn')});
	
}
else if (DateCompare(now(), prevtime) gte 0){
	auctionType = 0;//预展
	structappend(listjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
	structappend(listjson,{"preETime":datetimeformat(starttime,'yyyy-mm-dd HH:nn')});
}
else {
	auctionType = -1;//待展
	structappend(listjson,{"preSTime":datetimeformat(prevtime,'yyyy-mm-dd HH:nn')});
}

structappend(listjson,{"auctionType":auctionType});

arrayappend(list,listjson);
</cfscript>
</cfoutput>
<cfscript>
StructAppend(rs,{"list":list});
if (isdefined('dump')){
	writedump(rs);
}
rs = createObject("component",'cfjson').encode(rs);
return rs;
</cfscript>

<!---<cfcatch type="any">
<cfreturn {"success":0}>
</cfcatch>
</cftry>--->
	</cffunction>
  
</cfcomponent>